package com.ruoyi.web.controller.kubernetes;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.KubernetesGroupRoleBinding;
import com.ruoyi.web.service.IKubernetesGroupRoleBindingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * K8s组权限Controller
 *
 * @author xuchengchao
 * @date 2022-04-17
 */
@RestController
@RequestMapping("/kubernetes/group_binding")
public class KubernetesGroupRoleBindingController extends BaseController
{
    @Autowired
    private IKubernetesGroupRoleBindingService kubernetesGroupRoleBindingService;

    /**
     * 查询K8s组权限列表
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group_binding:list')")
    @GetMapping("/list")
    public TableDataInfo list(KubernetesGroupRoleBinding kubernetesGroupRoleBinding)
    {
        startPage();
        List<KubernetesGroupRoleBinding> list = kubernetesGroupRoleBindingService.selectKubernetesGroupRoleBindingList(kubernetesGroupRoleBinding);
        return getDataTable(list);
    }

    /**
     * 导出K8s组权限列表
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group_binding:export')")
    @Log(title = "K8s组权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KubernetesGroupRoleBinding kubernetesGroupRoleBinding)
    {
        List<KubernetesGroupRoleBinding> list = kubernetesGroupRoleBindingService.selectKubernetesGroupRoleBindingList(kubernetesGroupRoleBinding);
        ExcelUtil<KubernetesGroupRoleBinding> util = new ExcelUtil<KubernetesGroupRoleBinding>(KubernetesGroupRoleBinding.class);
        util.exportExcel(response, list, "K8s组权限数据");
    }

    /**
     * 获取K8s组权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group_binding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kubernetesGroupRoleBindingService.selectKubernetesGroupRoleBindingById(id));
    }

    /**
     * 新增K8s组权限
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group_binding:add')")
    @Log(title = "K8s组权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KubernetesGroupRoleBinding kubernetesGroupRoleBinding)
    {
        return toAjax(kubernetesGroupRoleBindingService.insertKubernetesGroupRoleBinding(kubernetesGroupRoleBinding));
    }

    /**
     * 修改K8s组权限
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group_binding:edit')")
    @Log(title = "K8s组权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KubernetesGroupRoleBinding kubernetesGroupRoleBinding)
    {
        return toAjax(kubernetesGroupRoleBindingService.updateKubernetesGroupRoleBinding(kubernetesGroupRoleBinding));
    }

    /**
     * 删除K8s组权限
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group_binding:remove')")
    @Log(title = "K8s组权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kubernetesGroupRoleBindingService.deleteKubernetesGroupRoleBindingByIds(ids));
    }
}
